package com.trainbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trainbook.common.result.JsonResult;
import com.trainbook.entity.Site2site;
import com.trainbook.mapper.Site2siteMapper;
import com.trainbook.service.ISite2siteService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 站点与站点间相连的表 服务实现类
 * </p>
 *
 * @author Dempsey
 * @since 2020-11-27
 */
@Service
public class Site2siteServiceImpl extends ServiceImpl<Site2siteMapper, Site2site> implements ISite2siteService {

    /**
     * 删除一个站点间联系
     *
     * @param siteA
     * @param siteB
     * @return
     */
    @Override
    @Transactional
    public JsonResult removeSite2Site(int siteA, int siteB) {
        QueryWrapper<Site2site> site2siteQueryWrapper = new QueryWrapper<>();
        site2siteQueryWrapper.eq("siteA",siteA).eq("siteB",siteB).or().eq("siteA",siteB).eq("siteB",siteA);
        if(remove(site2siteQueryWrapper)){
            return JsonResult.success();
        }
        return JsonResult.error("没有该站点联系");
    }
}
